package com.xyz.spring.boot.thymeleaf.controller;

import com.xyz.spring.boot.thymeleaf.entity.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    @GetMapping({"/index", ""})
    public String index(Model model) {

        // 当个对象数据
        User user = new User();
        user.setId(1001);
        user.setUsername("xuyizhuo");
        user.setSex("man");
        user.setAge(20);

        // 保存数据到域中
        model.addAttribute("user", user);

        // 列表数据
        List<User> userList = new ArrayList<>();
        User userL = null;
        for (int i = 1; i <= 3; i++) {
            userL = new User();
            userL.setId(i);
            userL.setUsername("我是" + i);
            userL.setSex("woman");
            userL.setAge(17 + i);
            userList.add(userL);
        }
        model.addAttribute("userList", userList);

        model.addAttribute("thid", "thid");
        model.addAttribute("thclass", "thclass");


        return "index";
    }

}
